package com.example.demo02.controller;

import com.example.demo02.common.ResponseEntity;
import com.example.demo02.entity.TcPlat;
import com.example.demo02.form.TcPlatForm;
import com.example.demo02.service.TcPlatService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "/tcPlat")
public class TcPlatController {
    @Resource
    TcPlatService tcPlatService;


    @RequestMapping(value = "/getTcPlatListByPage", method = RequestMethod.POST)

    public ResponseEntity<Object> getTcPlatListByPage(@RequestBody TcPlatForm tcPlatForm) {
        try {
            List<TcPlat> tcPlatList = tcPlatService.getTcPlatListByPage(tcPlatForm);
            return ResponseEntity.success(PageInfo.of(tcPlatList));
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.error(e.getMessage());
        }finally {
            PageHelper.clearPage();
        }
    }
    @RequestMapping(value = "/saveOrUpdateTcPlat", method = RequestMethod.POST)
    public ResponseEntity<Object> saveOrUpdateTcPlat (@RequestBody TcPlatForm tcPlatForm){
        try {
            tcPlatService.saveOrUpdateTcPlat(tcPlatForm);
            return ResponseEntity.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResponseEntity.error(e.getMessage());
        }
    }
}
